import {UserActions} from './user';

const initialState = {
  busy_dates: [],
};

export const SupplierActions = {
  SUPPLIER_DETAIL_UPDATE: 'supplier_detail_update',
  SUPPLIER_DETAIL_RESET: 'supplier_detail_reset',
};

export function updateSupplier(payload) {
  return {
    type: SupplierActions.SUPPLIER_DETAIL_UPDATE,
    payload,
  };
}

export function resetSupplier(payload) {
  return {
    type: SupplierActions.SUPPLIER_DETAIL_RESET,
    payload,
  };
}

export default function supplier(state = initialState, action) {
  switch (action.type) {
    case SupplierActions.SUPPLIER_DETAIL_UPDATE:
      return {...state, ...action.payload};
    case SupplierActions.SUPPLIER_DETAIL_RESET:
      return initialState;
    case UserActions.USER_SIGN_OUT:
      return {
        busy_dates: [],
      };
    default:
      return state;
  }
}
